<template>
	<view>
		<view class="swiper square">
			<swiper class="skeleton-rect" indicator-dots="true"
				:autoplay="true" :circular="circular" :interval="interval" :duration="duration"
				indicator-color="rgba(255,255,255,0.6)" indicator-active-color="#fff" :current="swiperCur"
				@change="swiperChange" style="height: 400rpx;">
				<block v-for="(item,index) in carousels" :key="index">
					<swiper-item class="" :class="{active:index == swiperCur}">
						<view style="height: 400rpx;" @click="goDetail(item)" class='slide-navigator acea-row row-between-wrapper'>
							<image :src="item.cover" class="slide-image"></image>
						</view>
					</swiper-item>
				</block>
		
			</swiper>
		</view><!-- 轮播图 end -->
		<view class="info_container">
			<view class="funcs_bg">
				<view class="func_item" @click="gotoPublish(1)">
					<image class="item_icon" src="../../../static/images/funcs/ic_home_djkt.png"></image>
					<view class="item_text">普通发货</view>
				</view><!--func_item end-->
				<view class="func_item" @click="gotoPublish(2)">
					<image class="item_icon" src="../../../static/images/funcs/ic_home_djms.png"></image>
					<view class="item_text">拼车发货</view>
				</view><!--func_item end-->
				<view class="func_item" @click="gotoOrder()">
					<image class="item_icon" src="../../../static/images/funcs/ic_home_djxf.png"></image>
					<view class="item_text">我的订单</view>
				</view><!--func_item end-->
				<view class="func_item" @click="gotoVip()">
					<image class="item_icon" src="../../../static/images/funcs/ic_home_sjk.png"></image>
					<view class="item_text">会员权益</view>
				</view><!--func_item end-->
			</view><!-- funcs_bg end-->
			
			<view class="service_bg">
				<view class="sb_time" v-for="item in ads">
					<image class="vip_ads" :src="item.cover" mode="aspectFill"></image>
				</view>
			</view><!-- 营业时间 end-->
			
			<view class="products">
				<view class="top">
					<view class="top_title">发货中</view>
					<view class="top_more" @click="gotoMore()">
						<view class="more_text">更多</view>
						<image class="more_arrow" src="../../../static/images/arrow.png"></image>
					</view>
				</view>
				<view class="empty" v-if="doing_data.length == 0">
					<view class="empty_bg">
						<image class="empty_class" src="/static/images/empty_img.png"></image>
					</view>
					<view class="desc_bg">
						周围有
						<text class="red" v-if="driver>10000">{{driver/10000}}w+</text>
						<text class="red" v-else>{{driver}}</text>
						司机等您发货
					</view>
				</view>
				<view class="items" v-if="doing_data.length > 0">
					<view class="item" v-for="item in doing_data" @click="goDetails(item.id)">
						<view class="item_title">
							<view class="title">
							{{item.name}}【{{item.wrap_way}}】
							{{item.weight_start == item.weight_end?item.weight_start+"吨":item.weight_start+"-"+item.weight_end+"吨"}}
							{{item.volumn_start == item.volumn_end?item.volumn_start+"方":item.volumn_start+"-"+item.volumn_end+"方"}}
							</view>
							<view class="time">{{item.setup_time}}</view>
						</view><!--top end-->
						<view class="types">
							{{item.type == 0?'整车':'零担'}}  {{item.car_type_len}}
						</view><!--types end-->
						<view class="address_start">
							<view class="sta">装</view>
							<view class="address">{{item.start_province}}{{item.start_city}}{{item.start_distinct}}{{item.start_address}}</view>
						</view><!--address_start end-->
						<view class="address_end">
							<view class="end">卸</view>
							<view class="address">{{item.end_province}}{{item.end_city}}{{item.end_distinct}}{{item.end_address}}</view>
						</view><!--address_start end-->
					</view>
				</view>
			</view><!--product end-->
		</view><!--info-->
		
		
		<uni-popup ref="pop" class="popup-cls">
			<view class="pop-info">
				<view class="pop-top">
					<view class="cancel" @click="cancelTime()">
						取消
					</view>
					<view class="title">
						装货时间
					</view>
					<view class="confirm" @click="confirmTime()">
						确定
					</view>
				</view>
				<view class="center"> 
					<view class="top_bg">
						填写准确装货时间，可防司机误抢哦
					</view>
					<view class="pop-content">
						<scroll-view class="left" scroll-y="true">
							<view class="section" @click="selectDate(item)" :class="left_current==item?'selected':''" v-for="item in leftDate">{{item}}</view>
						</scroll-view>
						<scroll-view class="right" scroll-y="true">
							<view class="section" @click="selectTime(item)" :class="right_current==item?'selected':''" v-for="item in rightTime">{{item}}</view>
						</scroll-view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	
	import {getProductList} from "@/api/product.js";
	import {get_doing_top5,index} from "@/api/index.js";
	export default {
		data() {
			return {
				showSkeleton: true, //骨架屏显示隐藏
				indicatorDots: false,
				circular: true,
				autoplay: true,
				interval: 4000,
				duration: 500,
				imgUrls: [
					{
						'img':'https://play.bobahappy.com/uploads/attach/2023/02/20230223/a28a8eff20e25c087b6652d2061f5c10.jpg'
					},
					{
						'img':'https://play.bobahappy.com/uploads/attach/2023/02/20230223/348ace0041c4709400a939a2ab54a385.png'
					},
					{
						'img':'https://ss2.meipian.me/users/22728741/eef8848a058544ecb59e3c5bfaec8828.jpg'
					}
				], //图片轮播数据
				datas:[],
				doing_data:[],//发货中数据
				carousels:[],//轮播
				ads:[],//广告图
				driver:0,//司机数量
				leftDate:[],//左边日期
				left_current:'',//左边日期
				rightTime:[],//右边时间
				right_current:'',//右边日期
			}
		},
		onShareTimeline() {
			return {
				title: '拉货快',
				//分享朋友圈的参数
				query: "isShare=1&id=",
			}
		},
		onShareAppMessage(){
		},
		onLoad() {
			this.getIndex();
			this.getDoingData();
		},
		created() {
			//生成时间
			//左边
			var now = new Date();
			this.leftDate.push("今天");
			this.leftDate.push("今明两天均可");
			this.leftDate.push("明天("+this.getDay(1)+")");
			this.leftDate.push("后天("+this.getDay(2)+")");
			this.leftDate.push(this.getDay(3));
			this.leftDate.push(this.getDay(4));
			this.leftDate.push(this.getDay(5));
			this.leftDate.push(this.getDay(6));
			
			this.selectDate("今天");
		},
		methods: {
			selectDate(item){
				this.left_current = item;
				this.right_current = '';
				this.getTime(this.left_current);
			},
			selectTime(item){
				this.right_current = item;
			},
			getDay(add){
				var now = new Date();
				var month = now.getMonth()+1;
				if(month < 10){
					month = "0"+month;
				}
				var day = now.getDate()+add;
				if(day < 10){
					day = "0"+day;
				}
				return month + '-' + day;
			},
			getTime(date){
				this.rightTime = []; 
				if(date == '今天'){
					this.rightTime.push('自定义时间');
					this.rightTime.push('上午06:00-12:00');
					this.rightTime.push('下午12:00-18:00');
					this.rightTime.push('晚上18:00-24:00');
					this.rightTime.push('上午10:00');
					this.rightTime.push('上午11:00');
					this.rightTime.push('上午12:00');
					this.rightTime.push('下午13:00');
					this.rightTime.push('下午14:00');
					this.rightTime.push('下午15:00');
					this.rightTime.push('下午16:00');
					this.rightTime.push('下午17:00');
					this.rightTime.push('下午18:00');
					this.rightTime.push('晚上19:00');
					this.rightTime.push('晚上20:00');
					this.rightTime.push('晚上21:00');
					this.rightTime.push('晚上22:00');
					this.rightTime.push('晚上23:00');
					this.rightTime.push('晚上24:00');
				}else if(date == '今明两天均可'){
					this.rightTime.push('随到随装');
					this.rightTime.push('去前联系');
				}else{
					this.rightTime.push('自定义时间');
					this.rightTime.push('凌晨00:00-06:00');
					this.rightTime.push('上午06:00-12:00');
					this.rightTime.push('下午12:00-18:00');
					this.rightTime.push('晚上18:00-24:00');
					this.rightTime.push('凌晨01:00');
					this.rightTime.push('凌晨02:00');
					this.rightTime.push('凌晨03:00');
					this.rightTime.push('凌晨04:00');
					this.rightTime.push('凌晨05:00');
					this.rightTime.push('凌晨06:00');
					this.rightTime.push('上午07:00');
					this.rightTime.push('上午08:00');
					this.rightTime.push('上午09:00');
					this.rightTime.push('上午10:00');
					this.rightTime.push('上午11:00');
					this.rightTime.push('上午12:00');
					this.rightTime.push('下午13:00');
					this.rightTime.push('下午14:00');
					this.rightTime.push('下午15:00');
					this.rightTime.push('下午16:00');
					this.rightTime.push('下午17:00');
					this.rightTime.push('下午18:00');
					this.rightTime.push('晚上19:00');
					this.rightTime.push('晚上20:00');
					this.rightTime.push('晚上21:00');
					this.rightTime.push('晚上22:00');
					this.rightTime.push('晚上23:00');
					this.rightTime.push('晚上24:00');
				}
			},
			//发货
			gotoPublish(type){
				if(type == 1){ //普通发货
					uni.navigateTo({
						url:"/pages/news/publish/publish"
					})
				}else if(type == 2){ //零担发货
					uni.navigateTo({
						url:"/pages/news/publish/zero_publish"
					})
				}
			},
			gotoMore(){
				uni.navigateTo({
					url:'/pages/news/more/list'
				});
			},
			gotoVip(){
				uni.navigateTo({
					url:'/pages/news/vip/vip'
				})
			},
			//订单
			gotoOrder(){
				uni.navigateTo({
					url:'/pages/news/order/list'
				})
			},
			gotoArticle(){
				uni.navigateTo({
					url:'/pages/news/news_list/index'
				})
			},
			swiperChange(e){
				
			},
			goDetails(id){
				uni.navigateTo({
					url:'/pages/news/order/detail?id='+id
				})
			},
			//发货中的订单
			getDoingData(){
				let that = this;
				get_doing_top5({}).then((res) => {
					let data = res.data.list;
					that.doing_data = data;
				});
			},
			//轮播
			getIndex(){
				let that = this;
				index({}).then((res) => {
					let data = res.data;
					that.carousels = data.banners;
					that.ads = data.ads;
					that.driver = data.driver;
					if(data.driver < 100){
						that.driver = Math.floor(Math.random() * (100 - 50 + 1) ) + 50;
					}
				});
			}
		},
		 //时间戳的处理    
		filters: {
			formatDate: function(value) {
				var date = new Date(value);
				//date.setTime(value);
				var month = date.getMonth() + 1;
				if(month < 10){
					month = "0" + month;
				}
				var hours = date.getHours();
				if (hours < 10)
					hours = "0" + hours;
				var minutes = date.getMinutes();
				if (minutes < 10)
					minutes = "0" + minutes;
				var time = month + "-" + date.getDate() +
					" " + hours + ":" + minutes;
				return time;
			}
 
		},

	}
</script>

<style lang="scss" scope>
	view{
		background-color: white;
	}
	page{
		background-color: white;
	}
	.swiper{
		// mheight: 500rpx;
		padding: 0 0;
		.slide-image{
			width: 100%;
			height: 400rpx;
		}
	}
	
	.info_container{
		display: flex;
		flex-direction: column;
		padding: 20rpx;
		
		.funcs_bg{
			display: flex;
			flex-direction: row;
			// flex-wrap: nowrap;
			justify-content: space-between;
			background-color: white;
			padding: 30rpx;
			.func_item{
				display: flex;
				flex-direction: column;
				align-items: center;
				width: 20%;
				.item_icon{
					width: 80rpx;
					height: 80rpx;
				}
				.item_text{
					font-size: 28rpx;
					color: black;
					margin-top: 10rpx;
				}
			}
		}
		.service_bg{
			display: flex;
			flex-direction: column;
			background-color: white;
			margin-top: 10rpx;
			padding: 0rpx 0rpx;
			.sb_time{
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				align-items: center;
				.vip_ads{
					height: 132rpx;
					width: 100%;
				}
			}
			
		}
	
		.products{
			display: flex;
			flex-direction: column;
			margin-top: 10rpx;
			padding: 0rpx 0rpx;
				
			.top{
				height: 80rpx;
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				align-items: center;
				.top_title{
					font-weight: bold;
					color: black;
					font-size: 28rpx;
				}
				.top_more{
					display: flex;
					flex-direction: row;
					justify-content: space-between;
					align-items: center;
					.more_text{
						font-weight: bold;
						color: black;
						font-size: 28rpx;
					}
					.more_arrow{
						width: 26rpx;
						height:26rpx;
					}
				}
			}
			.empty{
				display: flex;
				flex-direction: column;
				justify-content:center;
				.empty_bg{
					display: flex;
					flex-direction: row;
					justify-content:center;
					margin-top: 100rpx;
					.empty_class{
						width:224rpx;
						height:146rpx;
					}
				}
				.desc_bg{
					text-align: center;
					font-size: 28rpx;
					color: black;
					margin-top: 40rpx;
					margin-bottom: 100rpx;
					.red{
						font-size: 42rpx;
						color: darkorange;
					}
				}
			}
			.items{
				display: flex;
				flex-direction: column;
				background-color: white;
				.item{
					display: flex;
					flex-direction: column;
					border: 1rpx solid #CCC;
					padding: 30rpx;
					border-radius: 10rpx;
					margin-bottom: 20rpx;
					.item_title{
						display: flex;
						flex-direction: row;
						justify-content: space-between;
						.title{
							color: black;
							font-size: 28rpx;
							font-weight: bold;
						}
						.time{
							color: black;
							font-size: 28rpx;
						}
					}
					.types{
						display: flex;
						flex-direction: row;
						font-size: 28rpx;
						color: black;
						margin-top: 10rpx;
					}
					.address_start{
						display: flex;
						flex-direction: row;
						// align-items: center;
						// height: 40rpx;
						margin-top: 10rpx;
						.sta{
							width: 40rpx;
							height:36rpx;
							background-color: #008CFF;
							color: white;
							font-size: 20rpx;
							text-align: center;
							line-height: 36rpx;
							border-radius: 6rpx;
						}
						.address{
							color: black;
							font-size: 28rpx;
							margin-left: 15rpx;
						}
					}
					.address_end{
						margin-top: 15rpx;
						display: flex;
						// flex-direction: row;
						align-items: center;
						// height: 40rpx;
						.end{
							width: 40rpx;
							height:36rpx;
							background-color: #FF8F00;
							color: white;
							font-size: 20rpx;
							text-align: center;
							line-height: 36rpx;
							border-radius: 6rpx;
						}
						.address{
							color: black;
							font-size: 28rpx;
							margin-left: 15rpx;
						}
					}
				}
			}
		}
		
		
	}
	/** 须知弹窗 **/
	.popup-cls{
		display: flex;
		flex-direction: column;
		.pop-info{
			width:100%;
			display: flex;
			flex-direction: column;
			border-radius: 20rpx;
			margin: 0 auto;
			background-color: white;
			.pop-top{
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				align-items: center;
				font-weight: bold;
				margin-top: 20rpx;
				text-align: center;
				padding-bottom: 30rpx;
				.cancel{
					font-size: 28rpx;
					color: dimgray;
					margin-left:30rpx;
					height: 60rpx;
					width: 130rpx;
					line-height: 60rpx;
				}
				.title{
					font-size: 30rpx;
					font-weight: bold;
				}
				.confirm{
					background-color: $uni-main-color;
					color: white;
					font-size: 28rpx;
					height: 60rpx;
					width: 130rpx;
					border-radius: 30rpx;
					line-height: 60rpx;
					margin-right:30rpx;
				}
			}
		}
		
		.center{
			width:100%;
			display: flex;
			flex-direction: column;
			.top_bg{
				background-color: oldlace;
				height: 80rpx;
				color: darkorange;
				font-size: 30rpx;
				line-height: 80rpx;
				padding-left: 30rpx;
			}
			.pop-content{
				padding: 0rpx 30rpx;
				display: flex;
				flex-direction: row;
				height: 500rpx;
				margin-top: 30rpx;
				.left{
					width: 280rpx;
					background-color: #f8f8f8;
					.section{
						padding-left: 30rpx;
						height: 80rpx;
						color: black;
						font-size: 28rpx;
						background-color: transparent;
						line-height: 80rpx;
					}
					.selected{
						background-color: white;
						color: darkorange;
						font-weight: bold;
					}
				}
				.right{
					margin-left: 30rpx;
					flex: 1;
					background-color: white;
					.section{
						height: 80rpx;
						color: black;
						font-size: 28rpx;
						line-height: 80rpx;
					}
					.selected{
						background-color: white;
						color: darkorange;
						font-weight: bold;
					}
				}
			}
		}
		
	}//popup-cls end
</style>
